package com.portico.dept.solarch

class NamedList implements Serializable {

    String listItemName ;
    String listItemValue ;

    static constraints = {
      listItemName blank:false, minSize:4
      listItemValue blank:false, minSize:1
    }

    String toString () {
      value
    }

	static mapping = {
		id composite: ['listItemName', 'listItemValue']
		version false
	}

  static final addNewNamedListItem(String name, String value) {
    List items = NamedList.list([listItemName:name, listItemValue:value]) ;
    if ( items == null || items.size() == 0  ) {
      new NamedList(listItemName:name, listItemValue:value ).save(failOnError:true);
    }
  }

   List getNamedList (String itemName) {
       findall "from NamedList where listItemName = :name ", ['name':itemName]
  }
}
